﻿using System;
using System.Collections;


namespace Chess_Model
{

    public class Queen : Piece
    {

        public Queen(Position aPosition, int aPlayer)
        {
            pos = aPosition;
            player = aPlayer;
        }


        //
        // Generates a list of new legal positions from the current position
        //      regardless of the other pieces' positions
        // Queen can move in horizontal, vertical, and diagonal in 4 directions,
        //      namely NORTH_EAST, NORTH_WEST, SOUTH_EAST, SOUTH_WEST
        //
        public override ArrayList getNextLegalMoves()
        {
            ArrayList moves = new ArrayList();

            // Generate moves in x-direction (horizontal)
            ChessUtilities.addHorizontalMoves(moves, pos.x, pos.y);

            // Generate moves in y-direction (vertical)
            ChessUtilities.addVerticalMoves(moves, pos.x, pos.y);

            // Generate moves in diagonal direction (NORTH_EAST)
            // Increment x, decrement y
            ChessUtilities.addDiagonalMoves(moves, pos.x, pos.y, 1, -1);

            // Generate moves in diagonal direction (NORTH_WEST)
            // Decrement x and y
            ChessUtilities.addDiagonalMoves(moves, pos.x, pos.y, -1, -1);

            // Generate moves in diagonal direction (SOUTH_EAST)
            // Incremet x and y
            ChessUtilities.addDiagonalMoves(moves, pos.x, pos.y, 1, 1);

            // Generate moves in diagonal direction (SOUTH_WEST)
            // Increment y, decrement x
            ChessUtilities.addDiagonalMoves(moves, pos.x, pos.y, -1, 1);

            return moves;
        }

        public override String toString()
        {
            return String.Format("{0}{1}", "Q", player);
        }

        //
        // Main method for testing
        //
        //public static void Main()
        //{
        //    Position pos = new Position(3, 4);
        //    Piece p = new Queen(pos, WHITE);
        //    ArrayList moves = p.getNextLegalMoves();

        //    printMoves(moves);
        //    Console.WriteLine("Position {0} generated {1}.", pos, moves.Count);

        //    Console.Read();
        //}

    }

}
